// initial state
// shape: [{ id, quantity }]

const state = {
  num:2,
  name:'张三'
}
const getters = {
  userInfo (state) {
    return `my name is ${name}, I am ${state.num}`;
  }
}
// actions
const actions = {
  decrement: ({ commit }) => commit('DECREMENT'),
  add: ({ commit }) => commit('ADD'),
  addAsync: ({ commit }) => {
      setTimeout(() => {
          commit('ADD')
          resolve()
      },1000)
  },
  updateName: ({ commit }) => {
    setTimeout(() => {
      commit('UPDATE_NAME','李四')
    },1000)
  }
}

// mutations
const mutations = {
  DECREMENT (state){
      state.num--
  },
  ADD (state){
      state.num+=2
  },
  UPDATE_NAME (state, name){
      commit(name,name)
  }
}

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}
